﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Sys_authority : System.Web.UI.Page
{
    PM.PMSys.authority authority = new PM.PMSys.authority();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //根据级别读取权限（只有超级管理员可查看）
            StringBuilder funs = new StringBuilder();
            StringBuilder enablefun = new StringBuilder();
            string sql = "select * from Sys_UserType where state='true' order by id";
            DataTable result = authority.GetAuthority(sql);
            foreach (DataRow rows in result.Rows)
            {
                funs.Append(authority.CreateAuthorityTable(rows["fun"].ToString(),rows["id"].ToString(),rows["typename"].ToString()));
                enablefun.Append(rows["enablefun"].ToString());
                enablefun.Append(",");
            }
            Permission.Value = enablefun.ToString();
            All.InnerHtml=funs.ToString();
        }
    }

    protected void Submit_Authority(object sender, EventArgs e)
    {
        if(this.TargetTable.Value!=string.Empty&&this.Permission.Value!=string.Empty)
        {
            //应该要检测字符串的合法性
            authority.Update_Authority(Permission.Value.ToString().Trim(), int.Parse(TargetTable.Value.ToString().Trim()));
            //    PM.Code.Web.alertmessage.ShowDialog("更新成功！");
            //else
            //    PM.Code.Web.alertmessage.ShowDialog("更新失败！");
            Response.Redirect(Request.Url.ToString()); 
        }
    }
}
